//
//  StuOrderCell.m
//  test
//
//  Created by 朱圳 on 2018/1/5.
//  Copyright © 2018年 朱圳. All rights reserved.
//

#import "StuOrderCell.h"

@implementation StuOrderCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createUI];
    }
    return self;
}
-(void)createUI{
    
    UILabel *timeLab = [[UILabel alloc]init];
    timeLab.text = @"2017-11-13\n9:00-9:45";
    timeLab.numberOfLines = 0;
    timeLab.textColor = [UIColor darkGrayColor];
    timeLab.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:timeLab];
    [timeLab mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self);
        make.centerY.mas_equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(ScreenWidth/3, 60));
    }];
    self.timeLab = timeLab;
    
    UILabel *nameLab = [[UILabel alloc]init];
    nameLab.text = @"张三";
    nameLab.textColor = [UIColor darkGrayColor];
    nameLab.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:nameLab];
    [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(timeLab.mas_right);
        make.centerY.mas_equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(ScreenWidth/3, 60));
    }];
    self.nameLab = nameLab;
    
    UILabel *operationLab = [[UILabel alloc]init];
    operationLab.textColor = [UIColor redColor];
    operationLab.text = @"已拒绝";
    operationLab.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:operationLab];
    [operationLab mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(nameLab.mas_right);
        make.centerY.mas_equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(ScreenWidth/3, 60));
    }];
    self.operationLab = operationLab;
    
    /**********************分割线******************************/
    //底部
    UIView *xview1 = [[UIView alloc]init];
    xview1.backgroundColor = [UIColor lightGrayColor];
    [self.contentView addSubview:xview1];
    [xview1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self);
        make.height.mas_equalTo(0.8);
        make.left.mas_equalTo(self);
        make.right.mas_equalTo(self);
    }];
    //竖线1
    UIView *xview2 = [[UIView alloc]init];
    xview2.backgroundColor = [UIColor lightGrayColor];
    [self.contentView addSubview:xview2];
    [xview2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(nameLab.mas_left);
        make.bottom.mas_equalTo(self);
        make.top.mas_equalTo(self);
        make.width.mas_equalTo(0.8);
    }];
    
    //竖线2
    UIView *xview3 = [[UIView alloc]init];
    xview3.backgroundColor = [UIColor lightGrayColor];
    [self.contentView addSubview:xview3];
    [xview3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(operationLab.mas_left);
        make.bottom.mas_equalTo(self);
        make.top.mas_equalTo(self);
        make.width.mas_equalTo(0.8);
    }];
}

-(void)setModel:(OrderModel *)model{
    _model = model;
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];// 创建一个时间格式化对象
    [dateFormatter setDateFormat:@"yyyy-MM-dd"]; //设定时间的格式
    NSArray *p=[[Utility getDateStringWithTimeStr:model.startTime] componentsSeparatedByString:@" "];
    NSArray *p2=[[Utility getDateStringWithTimeStr:model.endTime] componentsSeparatedByString:@" "];
    //NSLog(@"分割后的字符串：%@",p[1]);
    self.timeLab.text = [NSString stringWithFormat:@"%@\n%@-%@",p[0],p[1],p2[1]];
    
    self.nameLab.text = model.pname;
    if ([model.status isEqualToString:@"1"]) {
        

        self.operationLab.text = @"接受";
        self.operationLab.textColor = [UIColor colorWithRed:72/225.0 green:211/255.0 blue:86/255.0 alpha:1.0];
    }else if ([model.status isEqualToString:@"2"]){
        
        self.operationLab.text = @"拒绝";
        self.operationLab.textColor = [UIColor colorWithRed:219/225.0 green:83/255.0 blue:80/255.0 alpha:1.0];
    }else{
        self.operationLab.text = @"待处理";
        self.operationLab.textColor = [UIColor colorWithRed:219/225.0 green:83/255.0 blue:80/255.0 alpha:1.0];
    }}
@end

